package cn.dylan.basic.service.impl;

import cn.dylan.basic.mapper.BaseMapper;

import cn.dylan.basic.query.BaseQuery;
import cn.dylan.basic.service.IBaseService;
import cn.dylan.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
//不加@service注解  @Transactional可以继承
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T LoadById(Long id) {
        return baseMapper.LoadById(id);
    }

    @Transactional
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Transactional
    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Integer counts = baseMapper.queryCounts(query);
        List<T> datas = baseMapper.queryDatas(query);
        System.out.println(datas);
        System.out.println(counts);
        return new PageList<T>(counts,datas);
    }

    @Override
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }


}
